/****************************************************************************
*
* Description: operations with bits
* Created at: 24.06.06 16:42:59 UTC
*
* $Revision$
*
****************************************************************************/
#pragma once

#ifndef __common_bits_h__
#define __common_bits_h__

#define rore(value, size, shift)	((((value) >> (shift)) | ((value) << ((size) - (shift)))) & ((1 << (size)) - 1))
#define role(value, size, shift)	((((value) << (shift)) | ((value) >> ((size) - (shift)))) & ((1 << (size)) - 1))
#define ror(value, shift)			(( (value) >> (shift)) | ((value) << ((sizeof(value) << 3) - (shift))))
#define rol(value, shift)			(( (value) << (shift)) | ((value) >> ((sizeof(value) << 3) - (shift))))

#define bit_get(bits, pos)  (!!(((bits)[(pos) >> 3] >> ((pos) & 7)) & 1))
#define bit_set(bits, pos)  ((bits)[(pos) >> 3] |= 1 << ((pos) & 7))
#define bit_clr(bits, pos)  ((bits)[(pos) >> 3] &= ~(1 << ((pos) & 7)))
#define bit_inv(bits, pos)  ((bits)[(pos) >> 3] ^= 1 << ((pos) & 7))

#endif /* End of __common_bits_h__  */
